<template>
  <div>
    <span>&nbsp;</span>
    <el-form
      :inline="true"
      :model="excelDetailed"
      class="demo-form-inline"
      style="border-radius: 4px"
    >
      <span>&nbsp;</span>
      <span>&nbsp;</span>
      <el-form-item label="名称">
        <el-input v-model="excelDetailed.title" placeholder="名称" style="width:200px"></el-input>
      </el-form-item>
      <el-form-item label="最大金额">
        <el-input v-model="excelDetailed.max" placeholder="最大金额"></el-input>
      </el-form-item>
      <el-form-item label="时间">
        <el-col :span="18">
          <el-date-picker
            v-model="excelDetailed.time"
            type="daterange"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            range-separator=" | "
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <br />
      <span>&nbsp;</span>
      <span>&nbsp;</span>
      <el-form-item label="类型">
        <el-select v-model="excelDetailed.type" placeholder="类型">
          <el-option label="收入" value="1"></el-option>
          <el-option label="支出" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="最小金额">
        <el-input v-model="excelDetailed.min" placeholder="最小金额"></el-input>
      </el-form-item>
      <span>&nbsp;</span>
      <span>&nbsp;</span>
      <span>&nbsp;</span>
      <span>&nbsp;</span>
      <el-form-item>
        <el-button type="primary" @click="getExcelList()">查询</el-button>
        <el-button type="success" @click="empty">清空</el-button>
        <el-button type="info" @click="generateExcel()">导出</el-button>
      </el-form-item>
    </el-form>

    <el-table
      :data="excelDetailedList"
      border
      style="width: 100%"
      :row-class-name="tableRowClassName"
    >
      <el-table-column label="序号" width="100" align="center">
        <template slot-scope="scope">{{ (page - 1) * limit + scope.$index + 1 }}</template>
      </el-table-column>
      <el-table-column prop="gmtCreate" label="日期" align="center" width="220"></el-table-column>
      <el-table-column prop="title" label="明细" align="center" width="220"></el-table-column>
      <el-table-column prop="num" label="金额" align="center"></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-popover placement="bottom" width="200" trigger="click">
            {{description}}
            <el-button
              type="success"
              size="mini"
              round
              slot="reference"
              @click="getdescription(scope.row.id)"
            >查看备注</el-button>
          </el-popover>
        </template>
      </el-table-column>
      
    </el-table>

    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getExcelList"
    />
  </div>
</template>


<style>
.el-table .pay {
  background: #f5f5f500;
}

.el-table .income {
  background: #fbfcfb00;
}
</style>

<script>
import ExcelApi from "@/api/tools/excel";
import detailed from "@/api/zw/zwlb";

export default {
  data() {
    return {
      excelDetailed: {},
      excelDetailedList: [],
      page: 1, //当前页数
      total: 0, //总记录数
      limit: 10, //每页记录数
      description: ""
    };
  },
  created() {
    this.getExcelList();
  },
  methods: {
    generateExcel(){
      ExcelApi.generateExcel(this.excelDetailed).then(response =>{
        this.$message({
            type: "success",
            message: "生成Excel成功!"
          })
      })
    },
    getdescription(id){
      detailed.getDescription(id).then(response=>{
        this.description=response.data.description
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.type === "2") {
        return "pay";
      } else {
        return "income";
      }
    },
    empty() {
      this.excelDetailed = {};
      this.getExcelList();
    },
    getExcelList(page = 1) {
      this.page = page;
      ExcelApi.getExcelDetailed(this.page, this.limit, this.excelDetailed).then(
        response => {
          this.excelDetailedList = response.data.list.data.records;
          this.total = response.data.list.data.total;
         
        }
      );
    }
  }
};
</script>